﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using System.Data;
using System.Data.SqlClient;
using AutoBackupDatabase.ENT;
namespace AutoBackupDatabase.DAL
{
   public class GROUPROLEDAL
    {
       private DbConnection conn;
       public GROUPROLEDAL()
       {
           conn = new DbConnection();
       }
       public List<GROUPROLEENT> GET_GROUPROLE_ALL()
       {
           string query = string.Format("exec GET_GROUPROLE_ALL ");
           DataTable ds = conn.executeGetQuery(query);
           List<GROUPROLEENT> List = new List<GROUPROLEENT>();
           foreach (DataRow item in ds.Rows)
           {
               GROUPROLEENT GROUPROLEent = new GROUPROLEENT();
               GROUPROLEent.GROUPROLECODE = item["GROUPROLECODE"].ToString();
               GROUPROLEent.GROUPROLENAME = item["GROUPROLENAME"].ToString();
               GROUPROLEent.USERCREATE = item["USERCREATE"].ToString();
               GROUPROLEent.DATECREATE = DateTime.Parse(item["DATECREATE"].ToString());
               GROUPROLEent.USERUPDATE = item["USERUPDATE"].ToString();
               GROUPROLEent.LASTUPDATE = DateTime.Parse(item["LASTUPDATE"].ToString());
               List.Add(GROUPROLEent);
           }

           return List;
       }
       public bool INSERTGROUPROLE(GROUPROLEENT ent)
       {
           string query = "exec  INSERTGROUPROLE @GROUPROLECODE, @GROUPROLENAME,@USERCREATE";
           SqlParameter[] sqlParameters = new SqlParameter[3];

           sqlParameters[0] = new SqlParameter("@GROUPROLECODE", SqlDbType.NVarChar);
           sqlParameters[0].Value = Convert.ToString(ent.GROUPROLECODE);
           sqlParameters[1] = new SqlParameter("@GROUPROLENAME", SqlDbType.NVarChar);
           sqlParameters[1].Value = Convert.ToString(ent.GROUPROLENAME);

           sqlParameters[2] = new SqlParameter("@USERCREATE", SqlDbType.NVarChar);
           sqlParameters[2].Value = Convert.ToString(ent.USERCREATE);

           return conn.executeInsertQuery(query, sqlParameters);
       }
       public bool UPDATEGROUPROLEBYGROUPROLEID(GROUPROLEENT ent)
       {
           string query = "exec  UPDATEGROUPROLEBYGROUPROLEID @GROUPROLECODE,@GROUPROLENAME,@USERUPDATE";
           SqlParameter[] sqlParameters = new SqlParameter[3];
           sqlParameters[0] = new SqlParameter("@GROUPROLECODE", SqlDbType.VarChar);
           sqlParameters[0].Value = Convert.ToString(ent.GROUPROLECODE);
           sqlParameters[1] = new SqlParameter("@GROUPROLENAME", SqlDbType.NVarChar);
           sqlParameters[1].Value = Convert.ToString(ent.GROUPROLENAME);
           sqlParameters[2] = new SqlParameter("@USERUPDATE", SqlDbType.NVarChar);
           sqlParameters[2].Value = Convert.ToString(ent.USERCREATE);
           return conn.executeUpdateQuery(query, sqlParameters);
       }
       public bool DELTELEGROUPROLEBYGROUPROLEID(GROUPROLEENT ent)
       {
           string query = "exec  DELTELEGROUPROLEBYGROUPROLEID @GROUPROLECODE";
           SqlParameter[] sqlParameters = new SqlParameter[1];
           sqlParameters[0] = new SqlParameter("@GROUPROLECODE", SqlDbType.VarChar);
           sqlParameters[0].Value = Convert.ToString(ent.GROUPROLECODE);
           return conn.executeDeleteQuery(query, sqlParameters);
       }
    }
}
